package models

import (
	"encoding/json"
	"pkg/utils/jsonx"
)

type ResourcesLimits struct {
	CpuTime     int `json:"cpu_time"`
	MemoryBytes int `json:"memory_bytes"`
	StackBytes  int `json:"stack_bytes"`
	OutputBytes int `json:"output_bytes"`
}

type OutputResult struct {
	SubmissionID int64            `json:"submission_id"`
	Language     string           `json:"language"`
	Code         string           `json:"code"`
	Verdict      Verdict          `json:"verdict"`
	MaxTime      int              `json:"max_time"`
	MaxMemory    int              `json:"max_memory"`
	Result       []TestCaseResult `json:"result"`
}

func (o *OutputResult) String() string {
	jsonBytes, _ := json.MarshalIndent(o, "", "  ")
	return string(jsonBytes)
}

type TestCaseResult struct {
	CaseID   string  `json:"case_id"`
	Stdin    string  `json:"stdin"`
	Stdout   string  `json:"stdout"`
	Stderr   string  `json:"stderr"`
	Status   Verdict `json:"status"`
	Time     int     `json:"time"`
	Memory   int     `json:"memory"`
	Expected string  `json:"expected"` // 添加Expected字段
}

type Verdict string

const (
	Accepted             Verdict = "Accepted"
	WrongAnswer          Verdict = "WrongAnswer"
	TimeLimitExceeded    Verdict = "TimeLimitExceeded"
	MemoryLimitExceeded  Verdict = "MemoryLimitExceeded"
	RuntimeError         Verdict = "RuntimeError"
	RestrictedSystemCall Verdict = "RestrictedSystemCall"
	CompilationError     Verdict = "CompilationError"
	SystemError          Verdict = "SystemError"
)

type LanguageConfig struct {
	CompileCmd    string   `json:"compile_cmd"`
	RunCmd        string   `json:"run_cmd"`
	AllowSysCalls []string `json:"allow_sys_calls"`
}

type InputStruct struct {
	SubmissionID    int64           `json:"submission_id"`
	Language        string          `json:"language"`
	Code            string          `json:"code"`
	TestCases       []TestCase      `json:"test_cases"`
	ResourcesLimits ResourcesLimits `json:"resources_limits"`
	Message         string          `json:"message"`
	SeccompProfile  string          `json:"seccomp_profile"`
}

func (i InputStruct) String() string {
	jsonBytes, _ := jsonx.MarshalIndent(
		i,
		"",
		"  ",
	)
	return string(jsonBytes)
}

type TestCase struct {
	CaseID   int    `json:"case_id"`
	Stdin    string `json:"stdin"`
	Expected string `json:"expected"`
}
